#ifndef Q_OS_WIN
#include <windows.h>
#endif
#include "agecalctest.h"
#include <common/agecalc/agecalc.h>
#include <common/logger/logger.h>
AgeCalcTest::AgeCalcTest(QObject* parent) : QObject(parent)
{
}

void AgeCalcTest::testGetAgeByCode()
{
	// ===================11位年龄代码测试=========================
	QCOMPARE(AgeCalc::getAgeByCode("00101050726").toStdString(), "1岁");
	QCOMPARE(AgeCalc::getAgeByCode("00101050726", true).toStdString(), "1岁");
	QCOMPARE(AgeCalc::getAgeByCode("07801050726", false).toStdString(), "78岁");
	QCOMPARE(AgeCalc::getAgeByCode("09101050726", false).toStdString(), "91岁");
	QCOMPARE(AgeCalc::getAgeByCode("00012050726", true).toStdString(), "12月");
	QCOMPARE(AgeCalc::getAgeByCode("00000000000").toStdString(), "");
	QCOMPARE(AgeCalc::getAgeByCode("00001050726").toStdString(), "1月");
	QCOMPARE(AgeCalc::getAgeByCode("00000050726").toStdString(), "5天");
	QCOMPARE(AgeCalc::getAgeByCode("00000310726").toStdString(), "31天");
	QCOMPARE(AgeCalc::getAgeByCode("00000000726").toStdString(), "7小时");
	QCOMPARE(AgeCalc::getAgeByCode("00000002326").toStdString(), "23小时");
	QCOMPARE(AgeCalc::getAgeByCode("00000000015").toStdString(), "");
	QCOMPARE(AgeCalc::getAgeByCode("00000000015", true).toStdString(), "15分钟");

	// ===================9位年龄代码测试=========================
	QCOMPARE(AgeCalc::getAgeByCode("001010507").toStdString(), "1岁");
	QCOMPARE(AgeCalc::getAgeByCode("001010507", true).toStdString(), "1岁");
	QCOMPARE(AgeCalc::getAgeByCode("078010507", false).toStdString(), "78岁");
	QCOMPARE(AgeCalc::getAgeByCode("091010507", false).toStdString(), "91岁");
	QCOMPARE(AgeCalc::getAgeByCode("000120507", true).toStdString(), "12月");
	QCOMPARE(AgeCalc::getAgeByCode("000000000").toStdString(), "");
	QCOMPARE(AgeCalc::getAgeByCode("000010507").toStdString(), "1月");
	QCOMPARE(AgeCalc::getAgeByCode("000000507").toStdString(), "5天");
	QCOMPARE(AgeCalc::getAgeByCode("000003107").toStdString(), "31天");
	QCOMPARE(AgeCalc::getAgeByCode("000000007").toStdString(), "7小时");
	QCOMPARE(AgeCalc::getAgeByCode("000000023").toStdString(), "23小时");
	QCOMPARE(AgeCalc::getAgeByCode("000000000").toStdString(), "");

	LOG_DEBUG("getAgeByCode未知测试", AgeCalc::getAgeByCode("000000000", true).toStdString());
}
void AgeCalcTest::testGetAgeCode()
{
	QDateTime calcDay = QDateTime::fromString("2025-09-24 17:09", "yyyy-MM-dd hh:mm");

	// ========== 合法情况 ==========

	// 1. 恰好 25 年零 0 月 0 日 (生日 == 2000-09-24 17:09)
	QDateTime birthDay = QDateTime::fromString("2000-09-24 17:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "025000000"); // 9 位
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "02500000009");// 11 位

	// 2. 25 年 1 天 (生日 == 2000-09-23 17:09)
	birthDay = QDateTime::fromString("2000-09-23 17:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "025000100");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "02500010004");

	// 3. 0 岁 0 月 1 天 0 小时 (刚出生 1 天)
	birthDay = QDateTime::fromString("2025-09-23 17:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "000000100");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "00000010004");

	// 4. 0 岁 0 月 0 天 1 小时 (刚出生 1 小时)
	birthDay = QDateTime::fromString("2025-09-24 16:09", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "000000001");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "00000000100");

	// 5. 0 岁 0 月 0 天 0 小时 1 分钟 (刚出生 1 分钟)
	birthDay = QDateTime::fromString("2025-09-24 17:08", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "000000000");// 分钟不计入 → 全 0
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "00000000001");

	// 6. 跨月：0 岁 1 月零几天 (生日 == 2025-08-20 17:09)
	birthDay = QDateTime::fromString("2025-08-20 17:08", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "000010400");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "00001040001");

	// 7. 跨年：5 岁 3 月 10 天 5 小时
	birthDay = QDateTime::fromString("2020-06-14 12:09", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "005031005");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "00503100500");

	// 8. 大跨度：99 岁 11 月 30 天
	birthDay = QDateTime::fromString("1925-10-25 00:00", "yyyy-MM-dd hh:mm");
	LOG_DEBUG("GetAgeCode跨年测试", AgeCalc::getAgeCode(birthDay, calcDay).toStdString());
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay).toStdString(), "099103017");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "09910301709");

	// ========== 非法情况 ==========

	// 9. 出生日期 > 计算日期 → 返回空
	birthDay = QDateTime::fromString("2026-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, false).toStdString(), "");
	QCOMPARE(AgeCalc::getAgeCode(birthDay, calcDay, true).toStdString(), "");
}

void AgeCalcTest::testCalcBirthDay()
{
	QDateTime calcDay = QDateTime::fromString("2025-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::calcBirthDay(calcDay, 10).toLocalTime().toString("yyyy-MM-dd hh:mm").toStdString(), "2015-01-01 00:00");
	QCOMPARE(AgeCalc::calcBirthDay(calcDay, 10, 1).toLocalTime().toString("yyyy-MM-dd hh:mm").toStdString(), "2014-12-01 00:00");
	QCOMPARE(AgeCalc::calcBirthDay(calcDay, 10, 1,14).toLocalTime().toString("yyyy-MM-dd hh:mm").toStdString(), "2014-11-17 00:00");
	QCOMPARE(AgeCalc::calcBirthDay(calcDay, 10, 1,14,22).toLocalTime().toString("yyyy-MM-dd hh:mm").toStdString(), "2014-11-16 02:00");
	QCOMPARE(AgeCalc::calcBirthDay(calcDay, 10, 1,14,22,17).toLocalTime().toString("yyyy-MM-dd hh:mm").toStdString(), "2014-11-16 01:43");

}

void AgeCalcTest::testGetAgeString()
{
	QDateTime birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	QDateTime calcDay = QDateTime::fromString("2020-01-01 00:00", "yyyy-MM-dd hh:mm");
	// 测试分钟级别的样例
	birthDay = QDateTime::fromString("2000-01-01 00:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 01:28", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "54分");
	// 分钟为0，小时级别的样例
	birthDay = QDateTime::fromString("2000-01-01 01:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 02:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1时");

	// 分钟+小时级别样例
	birthDay = QDateTime::fromString("2000-01-01 01:12", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 04:34", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "3时");

	// 分钟+小时级别样例(分钟借位)
	birthDay = QDateTime::fromString("2000-01-01 01:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 04:12", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "2时");

	//============以天为最大级别的测试===================
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1天");
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 01:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1天");
	birthDay = QDateTime::fromString("2000-01-01 01:08", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 03:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1天");
	// 借位测试
	birthDay = QDateTime::fromString("2000-01-01 02:32", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 04:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1天");
	birthDay = QDateTime::fromString("2000-01-01 02:32", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 01:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "22时");

	//======================以月为最大级别的测试===================
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 01:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-01 01:08", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 03:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-01 04:18", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 02:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-14 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "20天");
	birthDay = QDateTime::fromString("2000-01-14 08:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 07:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "19天");
	birthDay = QDateTime::fromString("2000-01-14 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "19天");
	birthDay = QDateTime::fromString("2000-01-10 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-11-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "9月");
	// 平年闰年测试
	birthDay = QDateTime::fromString("2000-02-14 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-03-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "17天");
	birthDay = QDateTime::fromString("2001-02-14 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-03-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "16天");

	// =====================以年为最大级别的测试===================
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 01:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2000-01-01 01:08", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 03:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2000-01-01 04:18", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 02:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "11月");
	birthDay = QDateTime::fromString("2000-05-14 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2020-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "19岁");
	birthDay = QDateTime::fromString("2000-01-01 00:01", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2020-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAgeString(birthDay, calcDay).toStdString(), "19岁");
}

void AgeCalcTest::testGetAgeByCodeInDH()
{
	//LOG_DEBUG("GetAgeByCodeInDH功能测试:  ",AgeCalc::getAgeByCodeInDH("01010221432").toStdString());

	QCOMPARE(AgeCalc::getAgeByCodeInDH("01010221432").toStdString(), "10岁10月");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("01510221432").toStdString(), "15岁");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("01410221432").toStdString(), "14岁");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00810221432").toStdString(), "8岁10月");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00700221432").toStdString(), "7岁");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00100221432").toStdString(), "1岁");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00010221432").toStdString(), "10月22天");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00001021432").toStdString(), "1月2天");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00000121432").toStdString(), "12天");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00000021432").toStdString(), "2天");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00000001232").toStdString(), "1天");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00000000032").toStdString(), "1天");
	QCOMPARE(AgeCalc::getAgeByCodeInDH("00000000000").toStdString(), "1天");
}
void AgeCalcTest::testGetAge()
{
	// ==========================format 为空测试===========================
	// 以下代码只走第一个if判断 相当于只走getAgeString
	QDateTime birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	QDateTime calcDay = QDateTime::fromString("2020-01-01 00:00", "yyyy-MM-dd hh:mm");
	QString f;
	// 测试分钟级别的样例
	birthDay = QDateTime::fromString("2000-01-01 00:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 01:28", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "54分");
	// 分钟为0，小时级别的样例
	birthDay = QDateTime::fromString("2000-01-01 01:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 02:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1时");

	// 分钟+小时级别样例
	birthDay = QDateTime::fromString("2000-01-01 01:12", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 04:34", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "3时");

	// 分钟+小时级别样例(分钟借位)
	birthDay = QDateTime::fromString("2000-01-01 01:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-01 04:12", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "2时");

	//============以天为最大级别的测试===================
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1天");
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 01:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1天");
	birthDay = QDateTime::fromString("2000-01-01 01:08", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 03:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1天");
	// 借位测试
	birthDay = QDateTime::fromString("2000-01-01 02:32", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 04:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1天");
	birthDay = QDateTime::fromString("2000-01-01 02:32", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-01-02 01:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "22时");

	//======================以月为最大级别的测试===================
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 01:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-01 01:08", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 03:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-01 04:18", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 02:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1月");
	birthDay = QDateTime::fromString("2000-01-14 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "20天");
	birthDay = QDateTime::fromString("2000-01-14 08:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 07:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "19天");
	birthDay = QDateTime::fromString("2000-01-14 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-02-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "19天");
	birthDay = QDateTime::fromString("2000-01-10 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-11-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "9月");
	// 平年闰年测试
	birthDay = QDateTime::fromString("2000-02-14 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2000-03-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "17天");
	birthDay = QDateTime::fromString("2001-02-14 08:34", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-03-03 07:26", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "16天");

	// =====================以年为最大级别的测试===================
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2000-01-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 01:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2000-01-01 01:08", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 03:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2000-01-01 04:18", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2001-01-01 02:05", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "11月");
	birthDay = QDateTime::fromString("2000-05-14 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2020-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "19岁");
	birthDay = QDateTime::fromString("2000-01-01 00:01", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2020-01-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,f).toStdString(), "19岁");
	// ===================================测试isEmr 和 zeroUnit===================================
	/**
	 * format解释
 	 * 14岁以上显示年龄,14岁到1岁显示年月,12月到6月显示月,6月到1月显示月日,
 	 * 不足一月大于10天显示日,不足10天显示日时,24小时到10小时显示小时,不足一天显示时分
	 */
	QString format = "1(14)|2(14,1)|3(12,6)|4(6,1)|5(31,10)|6(10,1)|7(24,10)|8(10,0)";

	birthDay = QDateTime::currentDateTime();
	calcDay = QDateTime::currentDateTime();

	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format,true,QString("新生儿")).toStdString(), "0新生儿");
	// ===================================format 不为空测试=========================================
	// 按照格式化的样式输出 有8个模式 年 年月 月 月日 日 日时 时 时分
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2025-02-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "21岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-02-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "14岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-03-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "14岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-02-27 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "14岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-02-26 01:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "14岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-02-26 00:01", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "14岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-01-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "13岁11月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-02-25 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "13岁11月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-02-25 23:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "13岁11月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2018-02-25 23:50", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "13岁11月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-02-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-03-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1岁1月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-02-27 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-02-26 05:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-02-26 05:10", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1岁");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2015-07-31 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "11岁5月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2015-07-15 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "11岁4月");

	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-01-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "11月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-02-25 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "11月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-02-25 23:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "11月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2005-02-25 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "11月");

	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-08-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "6月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-08-27 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "6月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-08-26 23:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "6月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-08-26 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "6月");

	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-08-25 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "5月30天");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-08-25 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "5月30天");

	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-03-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-03-26 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1月");
	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-03-25 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "28天");

	birthDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-03-25 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "28天");

	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-26 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "10天");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-26 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "10天");

	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-25 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "9天");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-25 23:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "9天23小时");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-25 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "9天23小时");

	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-17 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1天");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-17 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "1天23小时");

	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-16 23:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "23小时");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-16 14:59", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "14小时");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-16 10:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "10小时");

	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-16 08:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "8小时");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-16 10:01", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "10小时");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-16 09:59", "yyyy-MM-dd hh:mm");

	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "9小时59分钟");
	birthDay = QDateTime::fromString("2004-02-16 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2004-02-16 07:23", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getAge(birthDay, calcDay,format).toStdString(), "7小时23分钟");

}
void AgeCalcTest::testGetNewBabyAgeString()
{
	QDateTime birthDay = QDateTime::fromString("2025-06-01 00:00", "yyyy-MM-dd hh:mm");
	QDateTime calcDay = QDateTime::fromString("2025-09-16 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getNewBabyAgeString(birthDay, calcDay).toStdString(),"3 15/30");

	birthDay = QDateTime::fromString("2025-04-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2025-09-01 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getNewBabyAgeString(birthDay, calcDay).toStdString(),"5");

	birthDay = QDateTime::fromString("2025-09-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2025-09-21 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getNewBabyAgeString(birthDay, calcDay).toStdString(),"20/30");
	birthDay = QDateTime::fromString("2025-09-21 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2025-09-21 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getNewBabyAgeString(birthDay, calcDay).toStdString(),"0/30");
	birthDay = QDateTime::fromString("2024-10-01 00:00", "yyyy-MM-dd hh:mm");
	calcDay = QDateTime::fromString("2025-09-30 00:00", "yyyy-MM-dd hh:mm");
	QCOMPARE(AgeCalc::getNewBabyAgeString(birthDay, calcDay).toStdString(),"11 29/30");

	QCOMPARE(AgeCalc::getNewBabyAgeString(birthDay, std::nullopt).toStdString(),"");
	QCOMPARE(AgeCalc::getNewBabyAgeString(std::nullopt, calcDay).toStdString(),"");
	QCOMPARE(AgeCalc::getNewBabyAgeString(std::nullopt, std::nullopt).toStdString(),"");

}
int main(int argc, char* argv[])
{
#ifdef Q_OS_WIN
	// 设置控制台输出代码页为 UTF-8
	SetConsoleOutputCP(CP_UTF8);
	// 可选：设置控制台输入为 UTF-8
	SetConsoleCP(CP_UTF8);
#endif
	AgeCalcTest tc;
	QTest::qExec(&tc, argc, argv);
}
